﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint;

namespace de.rwth.rz.campus.Mailer
{
    /// <remarks>
    /// 
    /// Copyright 2010 RWTH Aachen, CAMPUS Labs
    /// 
    /// Licensed under the Apache License, Version 2.0 (the "License");
    /// you may not use this file except in compliance with the License.
    /// You may obtain a copy of the License at
    ///
    /// http://www.apache.org/licenses/LICENSE-2.0
    ///
    /// Unless required by applicable law or agreed to in writing, software
    /// distributed under the License is distributed on an "AS IS" BASIS,
    /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    /// See the License for the specific language governing permissions and
    /// limitations under the License.
    /// 
    /// </remarks>

    [CLSCompliant(false)]
    public class SPProperties 
    {
        private SPPropertyBag properties;
        private SPWeb web;


        public String this[String key]
        {
            get {return this.GetValue(key); }
        }

        public SPProperties(SPWeb webCurrent)
        {
            this.web = webCurrent;
            properties = CurrentWeb.Properties;
        }

        public bool ExistsKey(String key)
        {
            return properties.ContainsKey(key);
        }

        protected String GetValue(String key)
        {
            if (ExistsKey(key))
            {
                return (String)properties[key];
            }
            else
            {
                return String.Empty;
            }
        }

        public void SetValue(String key, String Value)
        {
            if (ExistsKey(key))
            {
                properties[key] = Value;
            }
            else
            {
                properties.Add(key, Value);
            }

            properties.Update();
        }

        public void DeleteKey(String key)
        {
            properties.Remove(key);
            properties.Update();
        }

        public SPWeb CurrentWeb
        {
            get { return web; }
            set { web = value; }
        }
    }
}
